#!/usr/bin/perl -w

## example script to show how to use the Java classes from
## perl.

BEGIN {
  $ENV{'CLASSPATH'} = "./SemanticModels.jar:lib/semanticvectors-1.31.jar:lib/lucene-core-3.0.1.jar";
  if(!defined($ENV{'JAVA_OPTS'})) {
    $ENV{'JAVA_OPTS'} = '-Xmx1024m';
  }
}

use 5.010;
use strict;
use warnings;
# use feature 'unicode_strings';  #requires 5.012
use Inline
  Java => 'STUDY',
  STUDY => [
    qw( at.ofai.sail.gate.ri.TermComparator
        at.ofai.sail.gate.ri.TermSearcher
        java.util.List
      )
  ],
  EXTRA_JAVA_ARGS => $ENV{'JAVA_OPTS'},
  AUTOSTUDY => 1;

binmode(STDOUT,":utf8");



## 1) create a TermComparator class and get the similarity
## between two terms 

my $c = at::ofai::sail::gate::ri::TermComparator->new(
  "index/termvectors.bin","index/index","index/lemmas_distinct.lst","true");

my $score = $c->getSimilarity("Israels Hamas","Livni Gaza");
print "Score for 'Israels Hamas'/'Livni Gaza' is $score\n";

$score = $c->getSimilarity("blosib", "Israel");
print "Score for blosib/Israel: $score\n";

## 2) create a TermSearcher class and get matching terms for a 
## query term

my $s = at::ofai::sail::gate::ri::TermSearcher->new(
  "index/termvectors.bin","index/index");

print "Similar terms for israel:\n";
my $rets = $s->getSimilarTerms("israel",30)->toArray();
foreach my $m ( @{$rets} ) {
  my $score = $m->getScore();
  my $term  = $m->getTerm();
  # $term = encod
  print $score," ",$term,"\n";
}


